<template>
	<view class="" style="width: 100vw;height: 100vh">
		<view class="" :style="{'background':kbackgroundColor2}" style="min-height: 100vh">
			<hx-navbar title="钱包列表" :back="true" :fixed="false" :color="knavTitleColor" barPlaceholder="hidden"
				transparent="auto"></hx-navbar>
			<!-- <view class="content">
					<view class="money-box cell-item-ft fsz32" @click="sumpayCashier">
				<image class="bg-img" src="/static/user/sumday.png" mode="aspectFill"></image>
				<view class="cell-item-ft color-f z1">
					<image class="img" src="/static/image/sumpay.png" mode="aspectFill"></image>
					统统
				</view>
				<view class="open color-f fsz28 cell-item-cc">
					立即开通
				</view>
			</view> -->
			<view class="content">
				<!-- sumpayCashier   hfpayWalletClick-->
				<view class="money-box cell-item-ft fsz32" @click="tiopen('hf')">
					<image class="bg-img" src="/static/user/payto.png" mode="aspectFill"></image>
					<view class="cell-item-ft color-0 z1">
						<image class="img" src="/static/image/payto.png" mode="aspectFill"></image>
						汇付天下
					</view>
					<view class="payopen  fsz28 cell-item-cc" :style="[selStyle]">
						<text v-if="userInfo.walletStatus.hfStatus==0">去开通</text>
						<text v-else>我的钱包</text>
					</view>
				</view>
				<view class="money-box cell-item-ft fsz32" @click="tiopen('xt')">
					<image class="bg-img" src="/static/user/system_payto.png" mode="aspectFill"></image>
					<view class="cell-item-ft color-0 z1">
						<image class="img" src="/static/logo.png" mode="aspectFill"></image>
						系统钱包
					</view>
					<view class="payopen  fsz28 cell-item-cc" :style="[selStyle]">
						<text v-if="userInfo.walletStatus.xtStatus==0">去开通</text>
						<text v-else>我的钱包</text>
					</view>
				</view>
				<!-- @click="getOpenAccount()" -->
				<!-- <view class="money-box cell-item-ft fsz32" >
				<image class="bg-img" src="/static/user/sd1.png" mode="aspectFill"></image>
				<view class="cell-item-ft color-f z1">
					<image class="img" src="/static/user/hf.png" mode="aspectFill"></image>
					汇付
				</view>
				<view class="open1 color-f fsz28 cell-item-cc" v-if="userInfo.is_kaihu==0">
					待上线
				</view>
				<view class="open1 color-f fsz28 cell-item-cc" v-else>
					已开通
				</view>
			</view> -->
				<view class="money-box cell-item-ft fsz32" @click="tiopen('sd')">
					<image class="bg-img" src="/static/user/sd2.png" mode="aspectFill"></image>
					<view class="cell-item-ft color-0 z1">
						<image class="img" src="/static/image/sandpay.png" mode="aspectFill"></image>
						杉德支付
					</view>
					<view class="payopen  fsz28 cell-item-cc" :style="[selStyle]">
						<text v-if="userInfo.walletStatus.sdStatus==0">去开通</text>
						<text v-else>我的钱包</text>
					</view>
				</view>
				<uni-popup ref="openXt" type="center" :maskBackgroundColor="'rgba(0,0,0,0.5)'" :isMaskClick="false">
					<view class="store-view store-border-all tips-padding"
						:style="{'background':kbackgroundColor,color:knormalColor}"
						:class="[{'alert-border-black alert-border-shadow-black':ktheme =='black'},{'alert-border-purple':ktheme =='purple'}]">
						<text class="popup-title">提示</text>
						<text class="popup-subtitle">您的操作将会开通系统钱包</text>
						<view class="tips-bottom">
							<view class="tips-button"
								:class="[{'tips-cancel-bg-black':ktheme =='black'},{'tips-cancel-bg-white':ktheme =='purple'}]"
								@click="openXtClose()">暂不开通</view>
							<view class="tips-button" :style="{background:kbuttonBgColor}" @click="openXtCheck()"> 继续开通
							</view>
						</view>
					</view>
				</uni-popup>
				<!-- 未实名 -->
				<uni-popup ref="bindingDialog" type="center" :maskBackgroundColor="'rgba(0,0,0,0.5)'"
					:isMaskClick="false">
					<view class="store-view store-border-all tips-padding"
						:style="{'background':kbackgroundColor,color:knormalColor}"
						:class="[{'alert-border-black alert-border-shadow-black':ktheme =='black'},{'alert-border-purple':ktheme =='purple'}]">
						<text class="popup-title">提示</text>
						<text class="popup-subtitle">您还未进行实名认证，请先完成实名认证!</text>
						<view class="tips-bottom">
							<view class="tips-button"
								:class="[{'tips-cancel-bg-black':ktheme =='black'},{'tips-cancel-bg-white':ktheme =='purple'}]"
								@click="bindingClose()">关闭</view>
							<view class="tips-button" :style="{background:kbuttonBgColor}" @click="bindingCheck()">去认证
							</view>
						</view>
					</view>
				</uni-popup>

				<uni-popup ref="thishiDialog" type="dialog">
					<uni-popup-dialog :type="msgType" cancelText="关闭" confirmText="跳转" title="提示" :content="thishiname"
						@confirm="thisConfirm" @close="thishiClose"></uni-popup-dialog>
				</uni-popup>
				<uni-popup ref="repetitionDialog" type="dialog">
					<uni-popup-dialog :type="msgType" cancelText="关闭" confirmText="跳转" title="提示" :content="tanname"
						@confirm="repetitionConfirm" @close="repetitionClose"></uni-popup-dialog>

				</uni-popup>
			</view>
			<!-- </view> -->
		</view>
	</view>
</template>
<script>
	import {
		sdwallet
	} from "../../../config/api";

	export default {
		data() {
			return {
				tiMesee: "",
				selStyle: {
					'--selectColorSize': this.$store.state.selectColorSize, //字体颜色
					'--buttonBcak': this.$store.state.buttonBcak, //按钮
					'--knavgroundColor':this.$store.state.knavgroundColor,
				},
				userInfo: {},
				msgType: "aa",
				tanname: "",
				account: {},
				thishiname: '前置钱包开户费2元,即享初始价值100元的老卢克版权商品',
				ywym_type: '',
			}
		},
		onShow() {
			this.$api.userInfo({}, res => {
				if (res.status) {
					this.userInfo = res.data
          if(res.data.walletStatus.hfStatus == 1 || res.data.walletStatus.sdStatus == 1) {
            // 已开户
            uni.setStorageSync('wallet_status', 'true')
          } else {
            uni.setStorageSync('wallet_status', 'false')
          }
				}
			})
			this.$api.userAccount({}, res => {
				if (res.status) {
					this.account = res.data
				}
			})
		},
		onPullDownRefresh() {
			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		methods: {
			bindingCheck() {
				this.$refs.bindingDialog.close()
				uni.navigateTo({
					url: '/pages/user/apply/apply'
				})
			},
			bindingClose() {
				this.$refs.bindingDialog.close()
			},
			thishiClose() {
				this.$refs.thishiDialog.close()
			},
			thisConfirm() {
				this.hfpayWalletClick()
				this.$refs.thishiDialog.close()
			},
			// 重复弹框关闭
			repetitionClose() {
				this.$refs.reDialog.close()
			},
			//重复弹框跳转
			repetitionConfirm() {
				uni.navigateTo({
					url: "/pages/user/apply/apply"
				})
				this.$refs.reDialog.close()
			},
			openXtClose() {
				this.$refs.openXt.close()
			},
			openXtCheck() {
				this.$refs.openXt.close()
				var data = {
						status: 1,
						type: 1
					}
					this.$api.savePurseAccount(data, res => {
						if (res.status) {
							uni.navigateTo({
								url: '/pages/user/wallet_system/wallet_system'
							})
						}else {
				     	this.$common.errorToShow(res.message);
				}
					})
			},
			getOpenAccount() { //汇付
				this.$api.openAccount({}, res => {
					if (res.status) {
						if (res.is_pay) {
							//#ifdef H5
							window.location.href = res.data
							// #endif
							//#ifdef APP-PLUS
							plus.runtime.openURL(res.data)
							// #endif
						} else {
							this.$common.navigateTo('/pages/payment/index?recharge=' + Number(res.data.money) +
								'&type=9')

						}

					}
				})
			},
			tiopen(val) {

				/**
				 */

				if (!this.account.isCertified) {
					this.$refs.bindingDialog.open()
				} else if (val == 'hf') {
					if (uni.getStorageSync('every_code')) {
						this.ywym_type = {
							type: 1
						}
					}
					if (this.ywym_type === 1) {
						this.$api.hfwallet(res => {
							if (res.status) {
								let url = res.data.url;
								// #ifdef H5
								window.location.href = url;
								// #endif
								// #ifdef APP-PLUS
								uni.navigateTo({
									url: '/pages/user/webview/webview?url=' + url
								})
								// #endif
							} else {
								uni.showToast({
									icon: "none",
									title: res.message
								})
							}
						}, this.ywym_type);
					} else {
						this.$api.hfwallet(res => {
							if (res.status) {
								let url = res.data.url;
								// #ifdef H5
								window.location.href = url;
								// #endif
								// #ifdef APP-PLUS
								uni.navigateTo({
									url: '/pages/user/webview/webview?url=' + url
								})
								// #endif
							} else {
								uni.showToast({
									icon: "none",
									title: res.message
								})
							}
						});
					}

				} else if (val == 'xt') {
					this.$api.checkSecondPassword({}, res => {
						if (res.status) {
							let data = res.data
							if (data.secondPassword) {
								this.savePurseAccount()
							} else {
								this.$common.errorToShow('请设置交易密码', () => {
									uni.navigateTo({
										url: '/pages/user/settings/pay_pass/pay_pass'
									})
								});
							}
						} else {
							this.$common.errorToShow('网络异常');
						}
					})
				} else if (val === 'sd') {
					this.$api.sdwallet(res => {
						if (res.status) {
							let url = res.data;
							// #ifdef H5
							window.location.href = url;
							// #endif
							// #ifdef APP-PLUS
							// plus.runtime.openURL(url)
							uni.setStorageSync('sdUrl', url);
							uni.navigateTo({
								url: `/pages/user/webview/sdWebview`
							})
							// #endif
						} else {
							uni.showToast({
								icon: "none",
								title: res.message
							})
						}
					}, this.ywym_type);
				}
			},
			savePurseAccount() {
				if (this.userInfo.walletStatus.xtStatus== 0) {
					this.$refs.openXt.open()
				} else {
					uni.navigateTo({
						url: '/pages/user/wallet_system/wallet_system'
					})

				}


	},
	hfpayWalletClick() {
			this.$api.hfpayWallet(res => {
				if (res.status) {
					// //#ifdef H5
					// window.location.href = res.data.redirect_url
					// // #endif
					// //#ifdef APP-PLUS
					// plus.runtime.openURL(res.data.redirect_url)
					// console.log("res.data.redirect_url---",res.data.redirect_url)
					// // #endif
					//#ifdef H5
					// uni.navigateTo({
					// 	url: '/pages/user/webview/webview?url=' + res.data.redirect_url
					// })
					window.location.href = res.data.redirect_url
					// #endif
					//#ifdef APP-PLUS
					// let style = {
					// 	statusbar: {
					// 		background: "#ffffff",
					// 	}
					// }
					// const wv = plus.webview.create(res.data.redirect_url, "", style);
					// wv.show()
					// uni.removeStorageSync("ifhuifu")
					// uni.setStorageSync('ifhuifu', 1);
					this.$store.commit('ifhuifu', 1)
					uni.navigateTo({
						url: '/pages/user/webview/webview?url=' + res.data.redirect_url
					})
					//#endif
				} else {
					this.tanname = res.msg
					this.$refs.repetitionDialog.open()

					//	this.$common.errorToShow(res.msg)
				}
			})
		},
		sumpayCashier() {
			this.$api.sumpayCashier({}, res => {
				console.log("res--", res)
				if (res.status) {

					//#ifdef H5
					window.location.href = res.data
					// #endif

					//#ifdef APP-PLUS
					plus.runtime.openURL(res.data)
					// #endif
				} else {

					this.$common.errorToShow(res.msg)
				}
			})
		},
		openUser() { //杉德
			this.$api.openUser({}, res => {
				if (res.status) {

					//#ifdef H5
					window.location.href = res.data
					// #endif

					//#ifdef APP-PLUS
					plus.runtime.openURL(res.data)
					// #endif
				}
			})
		}
	}
	}
</script>

<style scoped lang="scss">
	/deep/.uni-dialog-title-text {
		color: orange !important;
		font-size: 39rpx;
	}

	/deep/.uni-dialog-content-text {
		font-size: 35rpx;
	}

	.payopen {
		padding: 8rpx 20rpx;
		// width: 150rpx;
		// height: 56rpx;
		// background: linear-gradient(90deg, #FAA8BE 0%, #E9B8FA 100%);
		background: var(--buttonBcak);
		color: var(--knavgroundColor);
		border-radius: 28rpx;
		position: absolute;
		bottom: 88rpx;
		right: 38rpx;
	}

	.content {
		padding: 30rpx 40rpx;

		.money-box {
			width: 100%;
			height: 230rpx;
			position: relative;
			margin-bottom: 30rpx;
			padding: 0 36rpx;

			.open2 {

				background: #795FE1 !important;

			}

			.open1 {

				background: #5CA64B !important;

			}


			.open,
			.open1,
			.open2 {
				position: absolute;
				bottom: 0;
				right: 0;
				width: 131rpx;
				height: 44rpx;
				background: #5273C1;
				border-radius: 22rpx 0rpx 10rpx 0rpx;
			}

			.img {
				width: 90rpx;
				height: 90rpx;
				border-radius: 50%;
				margin-right: 20rpx;
			}

			.bg-img {
				position: absolute;
				z-index: 0;
				top: 0;
				left: 0;
				width: 100%;
				height: 230rpx;
				border-radius: 20rpx;
			}
		}
	}
</style>
